<%-- 
    Document   : tourTypeManage
    Created on : Aug 31, 2011, 9:40:24 PM
    Author     : HIEP
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<script>
    function validCar(){
        var name = document.forms["Cars"]["name"].value;
        var seatingCapacity = document.forms["Cars"]["seatingCapacity"].value;
        var price = document.forms["Cars"]["price"].value;
        var theFile = document.forms["Cars"]["theFile"].value;
        
        if(name == "" || name == null){
            alert("Please enter name of Car!");
            return false;
        }
        if(seatingCapacity == "" || seatingCapacity == null){
            alert("Please enter seating capacity of Car!");
            return false;
        }
        if(!seatingCapacity.match(/[0-9]/)){
            alert("Seating capacity must number");
            return false;
        }
        if(seatingCapacity < 1 || price ==null){
            alert("Seating capacity not valid!");
            return false;
        }
        if(price == "" || name == price){
            alert("Please enter price of Car!");
            return false;
        }
        if(!price.match(/[0-9]/)){
            alert("Price must number");
            return false;
        }
        if(price < 1 || price == null){
            alert("Price not valid!");
            return false;
        }
        if(theFile == "" || theFile == null){
            alert("Please enter Image of Car!");
            return false;
        }
        return true;
    } 
</script>

<%
    String path = "images/products/cars/";
%>

<!DOCTYPE html>
<div id="content" class="roundedBorders">
    <!-- Title -->
    <div id="title" class="b2">
        <h2>Manage Cars</h2>
    </div>
    <!-- Title -->
    <!-- Inner Content -->
    <div id="innerContent">
        <logic:empty name="item">
            <!-- Form -->
            <html:form onsubmit="return validCar();" action="/CarAction.do?method=add" enctype="multipart/form-data" method="POST">
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Add New Car</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <div class="field required">
                                <label>Name</label> 
                                <html:text property="name" value="" styleClass="text"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Seating Capacity</label> 
                                <html:text property="seatingCapacity" value="" styleClass="text"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Driver</label> 
                                <html:checkbox property="driver"/>
                            </div>
                            <div class="field required">
                                <label>Air Conditioner</label> 
                                <html:checkbox property="airConditioner"/>
                            </div> 
                            <div class="field required">
                                <label>Price</label> 
                                <html:text property="price" value="" styleClass="text"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Image</label> 
                                <html:file property="theFile"/>
                            </div>
                            <div class="field required">
                                <label>Model</label> 
                                <select name="model_id" style="width: 200px;">
                                    <c:forEach items="${modelList}" var="mode">
                                        <option value="${mode.id}">${mode.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Type</label> 
                                <select name="type_id" style="width: 200px;">
                                    <c:forEach items="${typeList}" var="type">
                                        <option value="${type.id}">${type.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Add Car" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <html:reset value="Reset" styleClass="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </logic:empty>
        <logic:notEmpty name="item">
            <!-- Form -->
            <html:form onsubmit="return validCar();" action="/CarAction.do?method=update" method="POST">
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Edit Car</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <div class="field required">
                                <label>Name</label> 
                                <html:text styleClass="text" property="name" name="item"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Seating Capacity</label> 
                                <html:text styleClass="text" property="seatingCapacity" name="item"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Driver</label> 
                                <html:checkbox property="driver" name="item"/>
                            </div>
                            <div class="field required">
                                <label>Air Conditioner</label> 
                                <html:checkbox property="airConditioner" name="item"/>
                            </div> 
                            <div class="field required">
                                <label>Price</label> 
                                <html:text property="price" styleClass="text" name="item"/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Image</label>
                                <html:hidden name="item" property="images"/>
                                <img src="<%=path%>${item.images}" height="100px" width="150px"/>
                            </div>
                            <div class="field required">
                                <label>Model</label> 
                                <select name="model_id" style="width: 200px;">
                                    <c:forEach items="${modelList}" var="mode">
                                        <c:if test="${mode.id == item.modelId}">
                                            <option selected="selected" value="${mode.id}">${mode.name}</option>
                                        </c:if>
                                        <option value="${mode.id}">${mode.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Type</label> 
                                <select name="type_id" style="width: 200px;">
                                    <c:forEach items="${typeList}" var="type">
                                        <c:if test="${type.id == item.typeId}">
                                            <option selected="selected" value="${type.id}">${type.name}</option>
                                        </c:if>
                                        <option value="${type.id}">${type.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Update" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <html:cancel value="Cancel" styleClass="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </logic:notEmpty>

    </div>
    <!-- /Inner Content -->
    <div class="bBottom"><div></div></div>
</div>
